unit UFrmReposicao;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Wwdbigrd, Grids, Wwdbgrid, RXCtrls, ExtCtrls, Mask,
  DBCtrls;

type
  TFrmReposicao = class(TForm)
    GroupBox1: TGroupBox;
    wwDBGrid1: TwwDBGrid;
    wwDBGrid1IButton: TwwIButton;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    RxLabel1: TRxLabel;
    Panel1: TPanel;
    DBEdit1: TDBEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    RxLabel2: TRxLabel;
    Image1: TImage;
    Bevel1: TBevel;
    btnRetornar: TSpeedButton;
    Bevel2: TBevel;
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure btnRetornarClick(Sender: TObject);
    procedure wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BitBtn1Click(Sender: TObject);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmReposicao: TFrmReposicao;
  vestoque : Integer;

implementation

uses Modulo;

{$R *.DFM}

procedure TFrmReposicao.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
   vBusca : String;
begin
  Case key of
    VK_Return:
     Begin
       if (Edit1.text = '') then
          begin
             ShowMessage('Digite um nome '+#13+
                      'para pesquisar!');
             Edit1.SetFocus;
             exit;
          end;
       if (Edit1.text <> '') then
          begin
              vBusca:='';
              DMEscola.Qconsultapro.Close;
              DMEscola.Qconsultapro.SQL.Clear;
              DMEscola.Qconsultapro.Sql.Add ('Select * From Produtos');
              DMEscola.Qconsultapro.Sql.Add('WHERE ');
              DMEscola.Qconsultapro.Sql.Add('(Descricao like :pNOME)');
              DMEscola.Qconsultapro.ParamByName('pNOME').AsString:='%'+Edit1.text+'%';
              DMEscola.Qconsultapro.open;
              vBusca:=DMEscola.QconsultaproDescricao.Text;
              vestoque := DMEscola.QconsultaproEstoque_Atual.AsInteger;
              If vBusca <> '' then
               begin
                  wwDBGrid1.visible:=True;
                  wwDBGrid1.setfocus;
                  Edit1.Text := '';
                  Panel1.Visible := false
               end
               else
               begin
                  ShowMessage('Produto não encontrado! Tente Novamente.');
                  Edit1.Text := '';
                  Edit1.SetFocus
               end;
              end;
       end;
  end;
end;

procedure TFrmReposicao.SpeedButton1Click(Sender: TObject);
var
   vBusca : String;
begin
   if (Edit1.text = '') then
   begin
      ShowMessage('Digite um nome '+#13+
                  'para pesquisar!');
      Edit1.SetFocus;
      exit;
   end;
   if (Edit1.text <> '') then
   begin
      vBusca:='';
      DMEscola.Qconsultapro.Close;
      DMEscola.Qconsultapro.SQL.Clear;
      DMEscola.Qconsultapro.Sql.Add ('Select * From Produtos');
      DMEscola.Qconsultapro.Sql.Add('WHERE ');
      DMEscola.Qconsultapro.Sql.Add('(Descricao like :pNOME)');
      DMEscola.Qconsultapro.ParamByName('pNOME').AsString:='%'+Edit1.text+'%';
      DMEscola.Qconsultapro.open;
      vBusca:=DMEscola.QconsultaproDescricao.Text;
      vestoque := DMEscola.QconsultaproEstoque_Atual.AsInteger;
      If vBusca <> '' then
      begin
         wwDBGrid1.visible:=True;
         wwDBGrid1.setfocus;
         Edit1.Text := '';
         Panel1.visible := false
      end
      else
      begin
         ShowMessage('Produto não encontrado! Tente Novamente.');
         Edit1.Text := '';
         Edit1.SetFocus
      end;
   end;
end;


procedure TFrmReposicao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   Action := CaFree;
end;

procedure TFrmReposicao.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
   if MessageDlg('Deseja realmente fechar o controle de Reposição de produtos?', MtConfirmation, [mbyes, mbno], 0) = mrno then
      CanClose := False;
end;

procedure TFrmReposicao.btnRetornarClick(Sender: TObject);
begin
   Close;
end;

procedure TFrmReposicao.wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 Case Key of
   VK_Return:
    Begin
       wwDBGrid1.visible:=False;
       Panel1.visible := true;
       Edit2.setFocus;
    end;
   VK_Escape:
    Begin
       wwDBGrid1.visible:=False;
       Panel1.visible := false;
       Edit1.setFocus;
    end;

 end;
end;

procedure TFrmReposicao.BitBtn1Click(Sender: TObject);
var
  x : string;
begin
   DMEscola.Qconsultapro.Edit;
   DMEscola.QconsultaproEstoque_Atual.Value := vestoque + StrToInt(Edit2.Text);
   DMEscola.Qconsultapro.Post;
   x  := IntToStr(DMEscola.QconsultaproEstoque_Atual.AsInteger);
   ShowMessage('Quantidade Total de '+DBEdit1.Text+' no momento é de '+x);
   Edit1.SetFocus;
   Panel1.Visible := false;
end;

procedure TFrmReposicao.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
   if Key = #13 then
   begin
      Key := #0;
      PostMessage(Handle, WM_NEXTDLGCTL, 0, 0)
   end;
end;



end.
